home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
INFOTEXT
/
ZBOOK.LZH
/
CH1-3.TXT
next >
Wrap
Text File
|
1988-03-24
|
22KB
|
482 lines
.T:ch.fmt
.K:I. DIGITAL ARITHMETIC
I. DIGITAL ARITHMETIC
.I:binary
Most modern computers are digital computers, based on the binary
or base two number system. In a decimal or base ten number, the
least significant or rightmost digit represents the number of ones,
the next tens, then hundreds, and so forth. If we call the least
significant digit the 0th then the Nth digit represents the number
of 10Ns. In binary, the Nth digit represents the number of 2Ns.
Thus 101 decimal means 1*102 + 0*10 + 1 while 101 binary is 1*22 +
0*2 + 1, or decimal five. When we refer to numbers in different
bases we will identify the base by writing it as a subscript after
the number. For example, 1110 is decimal eleven while 112 is the
binary equivalent of decimal three.
decimal: 10110 = 1 * 102 + 0 * 101 + 1 * 100
binary: 1012 = 1 * 22 + 0 * 21 + 1 * 20
= 4 + 0 + 1 = 510
.I:bit
.I:byte
Binary numbers use only the digits 0 and 1, represented in
computers by transistors in either the on (=1) or off (=0) state.
A binary digit is called a bit. A byte is an eight-digit binary
number.
bit: 0 byte: 11010011 (eight bits)
A byte may be transmitted from one group of eight transistors to
another over eight wires or lines, through each of which current
will flow only if the transistor to which that line is attached is
on. If we were to base a computer on the decimal number system,
each transistor would have to be able to represent ten different
states corresponding to the digits 0 through 9. This is done in
mechanical adding machines by using gears with ten teeth but there
is no easy way to do this electronically.
.I:hexadecimal
Binary numbers quickly get too long to write conveniently. It
is much easier to write 123410 than its binary equivalent
100110100102. For this reason binary quantities are often
represented in hexadecimal (base sixteen) to make them less
unwieldy. This is done by grouping bits by fours starting from the
right and converting each group to the corresponding hexadecimal
digit as shown in Table 1-1. Since the hexadecimal number system
reqires sixteen symbols for digits, the letters A through F are
used to represent the decimal quantities ten through fifteen. Thus
100110100102 = 100 1101 0010 = 4D216
.I:octal
Octal or base eight is also used as a shorthand for binary, but
not as often as hexadecimal. A byte breaks neatly into two
hexadecimal digits but makes two and a half octal digits. To
convert from binary to octal, group bits by threes instead of fours
and convert to digits in the group 0 through 7 (see Table 1-1).
.I:base interconversion
Converting back to binary from hexadecimal or octal is the same
process in reverse. To convert binary to decimal, multiply each
digit by the power of two it represents and add. Example:
.-
11012 = 1*23 + 1*22 + 0*2 + 1 = = 8 + 4 + 1 = 1310
.+
You could convert octal or hexadecimal numbers to decimal by
multiplying each digit by the appropriate power of eight or sixteen
(see Table 1) and adding, but you may find it easier to convert to
binary and from there to decimal. Converting decimal to binary is
most easily done by repeated integer division by two. Arranging
the remainders in the reverse of the order in which they were
obtained gives the binary result:
.-
13/2 = 6 r 1
6/2 = 3 r 0
3/2 = 1 r 1
1/2 = 0 r 1 --> 1101 = 1x8 + 1x4 + 0x2 + 1x1 = 13
.+
Binary numbers are added in the same way as their decimal
counterparts. Starting from the right, each pair of digits and any
carry in from the next lower place are added together to produce a
single digit sum and carry out:
.-
step: 1 2
carry: 0 10
1st: 11 11 11
2nd: +10 +10 +10
sum: 1 101
^ ^^
.+
.I:ones complement
.I:twos complement
.I:complement
.I:subtraction
Binary subtraction could be done like decimal subtraction, but
this is not how the microprocessor does it. By first making the
number to be subtracted a negative number and then adding it, the
microprocessor does away with the need for separate subtraction
circuitry. Fortunately it is quite easy to negate a binary number.
Just change all the zeros to ones and vice-versa (forming the ones
complement), then add one (forming the twos complement).
Forming the ones complement of some eight digit binary number X
is the same as subtracting it from 111111112 (try it). Forming the
twos complement by adding one to the ones complement amounts to
subtracting it from 1000000002. When we perform subtraction of a
binary number by adding its twos complement, the 1000000002
reappears as a carry out of the highest place (which we discard):
.-
Y + ~X = Y + 111111112 - X + 1
= Y - X + 1000000002
.+
In other words, to subtract X from Y, change all of the ones in X
to zeroes and the zeroes to ones, add one, add the result to Y, and
ignore the carry out of the highest place. Example:
.-
5 0101 0101 $ëëLÉèd∩└Σ H$═ô╚ê≤ê≥ 'æµ&Db╤'$$aéd≤≡Qÿææ°díD≤≤≤HττΓ'ττττττττττττττττττττττττττττπ#ππ#'α gπππ#'τα'τΓ88x `88x8gττττττττττ╔ g└└ '╞ └─ @τ└@ ╟ ┴ g╟ └τ└D ┴ D'└@ DB'└ τ┴╟ D'╟'└ D'°8gτττττττ╟ Dτ╟ └τ├└ ┴ D'└@ DB'╟'└D@'┴ g└┴─'└─@└ τ╞A αgτ└┴┴'┴'°8gτττττττ╞ └─τ└┴─'≡ g╞A ≡ gτ┬ F'└ D'╞A τ┴'└D─τ└└'┬D┬D @τ└┴─'°8gτττττττ┬ `τ└ D'└─'╞A τ┴'╟ G ╟@─'─@g└┴─'└ A └─ gτ└ ┴τ─└τ╞A ┬'°8gτττττττ└'╞ g┬D┬D @τα#"a±##±'└└'α#"`1##±'┴ g└└ '╞ └─ @τ└@ ╟ ┴ gor
unsigned numbers from 0 to 25510. Either way amounts to 25610
different numbers. Notice that the computer doesn't need to know
whether the numbers we are adding are twos complement signed
numbers or unsigned numbers:
.-
101 either 5 or -3
+010 equals 2 (signed or unsigned)
111 either 7 or -1
.+
.I:overflow
When the result of an arithmetic operation is too big to be
contained in the number of bits available, overflow has occurred.
For unsigned arithmetic this happens whenever there is a carry out
of the highest bit. For twos complement arithmetic, this happens
when the carries out of the two highest bits are not equal.
Example:
.-
carry: 10000 (The carry out of the highest bit is lost)
1st: 1001 (9 or -7)
2nd: +1010 (10 or -6)
sum: 0011 (3. Should be 19 or -13)
.+
Sometimes you can get away with mixing signed and unsigned
numbers, but the usual overflow tests will not work. for example:
.-
1010 10 unsigned
+1110 -2 signed
1000 8 unsigned
.+
Binary multiplication and division work just like their decimal
counterparts, but only on unsigned numbers. To perform these
operations on signed (twos complement) numbers, use their absolute
values and work out the sign of the result later.
.-
110 101
x101 110 /11110
110 110
000 110
110 110
11110
.+
.-
Problems
1. Convert each number below to the other two bases:
binary dec hex
1011
110010
101101
23
47
113
2C
D3
.+
2. Convert the decimal numbers in each exercise below to binary,
work the problem with the binary numbers, then convert the answer
back to decimal to check your answer. Use twos complement
arithmetic for negative numbers.
.-
a) 5+7 b) 12+16 c) 17+23 d) 53+27
e) 7-5 f) 19-3 g) 25-10 h) 48-31
i) 9*6 j) 20*13 k) 35/5 l) 144/6
.+
.K:Logic
II. LOGIC
.I:gates
.I:logic
At the heart of all digital computers lie circuits called logic
gates, each made up of only a few transistors. These are combined
in different ways to produce most of the electronics in a computer.
Logic gates get their names from their similarity to the operators
of mathematical logic. Each has one output which is turned on only
for certain combinations of its inputs, each of which may be either
on or off. The actions of the three basic logic gates NOT, AND,
and OR reflect the common meanings of these words.
.I:inverter
.I:NOT
.I:AND
The inverter or NOT gate is the simplest logic gate. If its
input is on, the output is off, and vice versa. If we let 'on'
stand for the logical value 'true' and 'off' stand for 'false' then
the connection with mathematical logic becomes more apparent: the
output NOT A is true if the input A is false and false if it is
true. Similarly, the output of the AND gate is on only if all
inputs are on. Thus, for a two-input AND gate, the output A AND B
is on only if both inputs A and B are on.
.I:OR
.I:XOR
There are two kinds of OR gates derived from the inclusive and
exclusive OR operators. The inclusive OR statement A OR B is true
if either A or B or both are true. The exclusive OR statement A
XOR B is true if either A or B but not both are true. Thus, the
output of the OR gate is on if any input is but that of the XOR gate
is on only if the two inputs are different.
.I:NAND
.I:NOR
The NOR and NAND gates produce outputs which are the inverse of
those produced by the OR and AND gates. They are equivalent to NOT
(A OR B) and NOT (A AND B) respectively, and are what would be
obtained if the outputs of the OR or AND gates were passed through
an inverter. Thus, A NOR B is true only when both A and B are
false and A NAND B is false only when both are true.
.I:truth table
It is possible to completely describe the behavior of a logic
gate by listing all possible combinations of inputs and the
resulting outputs in a tabular form called a truth table. Here is
the truth table for the logic operators described above, shown with
the symbols most commonly used to represent these operators in
logical expressons. Study it.
NOT AND NAND OR NOR XOR
A B A A.B A.B A+B A+B A+OB
F F T F T F T F
F T T F T T F T
T F F F T T F T
T T F T F T F F
.I:adder, binary
Logic gates may be combined to perform more complex functions,
for example, binary addition. To add a pair of bits in a binary
number, we must calculate a sum (adding in any carry from the next
lower bit pair) and a carry out to the next higher bit pair. Let A
and B be the bits to be added, S the sum, Ci the carry in, and Co
the carry out. If we let FALSE stand for zero and TRUE for one,
then we can simulate the behavior of the binary functions S and Co
as follows:
.-
S = (A XOR B) XOR Ci and
Co = (A AND B) OR ((A XOR B) AND Ci)
.+
To prove this, let's work out the truth tables for these
expressons. First set out all the combinations of A, B, and Ci,
then calculate intermediate results, and finally combine these to
get S and Co:
.-
#1 #2 #3
A B Ci A XOR B #1 XOR Ci (=S) A AND B #1 AND Ci #2 OR #3 (=Co)
0 0 0 0 0 0 0 0
0 0 1 0 1 0 0 0
0 1 0 1 1 0 0 0
0 1 1 1 0 0 1 1
1 0 0 1 1 0 0 0
1 0 1 1 0 0 1 1
1 1 0 0 0 1 0 1
1 1 1 0 1 1 0 1
.+
A circuit to perform binary addition according to the above
equations is shown in Fig. 2-1. A circuit to add two bytes can be
constructed by connecting eight of these end to end.
.-
Problems
1. DeMorgan's laws state that
A AND B = (NOT A) NOR (NOT B) and
A OR B = (NOT A) NAND (NOT B)
.+
Prove these by working out the truth tables for the right and left
half of each equation to show they are identical.
2. A circuit whose output will be on if the two inputs are equal
(both on or both off), can be derived from the compound logical
expression
.-
( A AND B ) OR ( A NOR B ).
.+
Can you come up with a shorter solution?
3. Draw schematics for the circuits which correspond to these
expressions:
.-
a) A AND NOT B
b) A OR ( A AND B )
c) ( A NOR B ) XOR C
d) A AND B AND
.+
.K:III. Microcomputer system overview
III. MICROCOMPUTER SYSTEM OVERVIEW
.I:central processing unit
.I:memory
.I:I/O
.I:microprocessor
.I:integrated circuit
.I:microcomputer
What is a microprocessor? All computers, micro or otherwise,
have three main components: a central processing unit which does
the computing, memory to store programs and data, and I/O or input-
output circuitry to communicate with the outside world. A
microprocessor is a central processing unit built into a single
integrated circuit. An integrated circuit is a single chip of
semiconductor material, the stuff of transistors, but containing up
to millions of transistors. Before the advent of integrated
circuits (also called ICs or chips), the central processor
typically took up many circuit boards. A computer which uses a
microprocessor is a microcomputer.
.I:microcomputer, single chip
.I:microcontroller
Integrated circuit technology has progressed to the point that
it is now possible to get a central processor, memory, and I/O
circuitry all on one chip. These single-chip microcomputers or
microcontrollers do not have enough memory to make them useable as
general purpose computers but they are very cost-effective in
control applications and are widely used in cars, appliances, and
industrial automation. They are also used extensively in computers
as keyboard, display, disk, and other I/O controllers to relieve
the main processor of time-consuming I/O tasks.
.I:hardware
.I:program
.I:software
.I:instructions
.I:language, high level
.I:language, machine
The interaction of the microprocessor, memory, and I/O
circuitry, collectively called hardware, is controlled by a program
(software) which resides in memory. A program is composed of
instructions, each of which directs the microprocessor to perform a
specific task. The process of running a program begins with the
transfer of an instruction from memory to the microprocessor.
Instructions in a high level language such as BASIC consist of a
collection of English words, numbers, and symbols. In contrast,
instructions in machine language, the native language of the
microprocessor, consist entirely of binary numbers. Each
microprocessor has its own machine language into which programs
written in higher level languages must be translated before they
will run.
.I:address
The size of the numbers used to represent machine language
instructions depends on the microprocessor. All eight-bit
microprocessors transfer a byte of data at a time between the
microprocessor and memory. A machine language instruction will
consist of one or more bytes stored in consecutive locations in
memory. Each memory location has a unique address which must be
supplied to memory by the microprocessor to specify the location of
the byte to be transferred. Most eight-bit microprocessors use
sixteen-bit addresses.
.I:op code
The first byte of an instruction is usually the op code, a
number which specifies the operation the microprocessor is to
perform. Some instructions consist only of an op code. In others,
one or more bytes of additional information follow. These may be a
number to be loaded into the microprocessor, an address, additional
information specifying the type of operation to be performed, or
some combination of these. There is no difference between the way
data and op codes are represented in memory. If the microprocessor
is expecting an op code, it will treat the byte it receives from
memory as an op code. If it is expecting data, it will treat it as
data.
.I:bus
Data and addresses are moved between the microprocessor and
memory or I/O chips on groups of lines called buses. The data bus
in an eight-bit microcomputer system consists of eight lines (wires
or printed circuit traces), each of can be either on or off. In
most microprocessors, a potential of 2 to 5 volts is on and 0 to .8
volts is off. The terms high and low are often used instead of on
and off.
Each data line and the pin or IC terminal to which it is
connected are represented by the letter D followed by a number
representing the magnitude of the bit it represents. D0 represents
the least significant bit (the number of 20s or ones) and D7 the
most significant (the number of 27s or 128s). If the binary number
10010010 is being transferred over the data bus then D7, D4, and D1
will be high and the others low. The address bus consists of
sixteen lines which transfer addresses from the microprocessor to
memory or I/O.
.I:control signal
.I:chip select signal
The data bus allows two-way communication between the
microprocessor and other system components. The direction of the
data transfer on the data bus is indicated to memory or I/O by a
control signal output by the microprocessor. This might be high
for a read (from memory or I/O) operation and low for a write (to
memory or I/O). Other control signals called chip select signals
are necessary to direct the flow of data and addresses to the right
chip. Usually these are active low, meaning that the memory or I/O
chip to which the signal is connected will be selected if the line
is low.
.I:bus, tri-state
When its chip select line is high, a memory or I/O chip is
electronically disconnected from the address and data buses. Lines
which can be electronically disconnected in this way are called
tri-state because they can be on, off, or disconnected (high
impedance). If all of the memory and I/O chips in a microcomputer
system have tri-state buses, then bringing only one chip select
line low at a time will result in only one memory or I/O chip being
connected to the microprocessor at a time. This reduces output
current requirements and prevents contention between two chips for
the data bus.
Problems
1. What is the difference between a microprocessor, a
microcomputer, and a microcontroller?
2. What are the three main components of a computer? What does
each do?
3. How does the microprocessor indicate which peripheral chip it
wants to communicate with? How does it indicate whether it intends
to send or receive data?
4. What do the data and address buses do? What are they connected
to?
5. What are the different possible components of a machine language
instruction?